package yxy.cherry.gateway;

import yxy.apple.util.concurrent.ThreadConfig;
import yxy.banana.launcher.JSONBeanConfiguration;
import yxy.cherry.game.base.mq.MqConfig;

public class Configuration extends yxy.banana.launcher.Configuration {
	static {
		SharedKey = "yxy.cherry.gateway.configuration.shared.key";
	}

	public static Configuration shared() {
		return JSONBeanConfiguration.shared(Configuration.SharedKey, Configuration.class);
	}

	public static class SSLClass {
		public boolean Enabled = false;
		public String CertificateFilename = null;
		public String PublicKeyFilename = null;
	}

	public static class WebSocketClass {
		public String Resource = "/gateway";
		public String Subprotocol = null;
	}

	public static class PortalClass {
		public String LocalIP = "0.0.0.0";
		public int LocalPort = 0;
		public SSLClass SSL = null;
		public WebSocketClass WebSocket = null;
	}

	public static class ExternalServerClass {

		public PortalClass[] Portals = null;
		public String LocalIP = "0.0.0.0";
		public int AcceptorThreads = 0;
		public int WorkThreads = 0;
		public int HeartbeatTimeout = 30000;
		public int AuthenticationTimeout = 10000;
		public int GatewayBeanExpiration = 1800000;// 半小时，取值应大于2倍HeartbeatTimeout
		public String Ethic = null;
	}

	public static class InternalClientClass {
		public String RouteCenterIP = "0.0.0.0";
		public int RouteCenterPort = 0;
		public int Channels = 0;
		public int Threads = 0;
		public int ReconnectInterval = 10000;
		public int HeartbeatInterval = 10000;
		public int HeartbeatResponseTimeout = 5000;
		public int HeartbeatResponseDelayAlertThreshold = 1000;
		public int RegistryResponseTimeout = 5000;
	}

	public static class RedisClass {
		public String Address = null;
		public String Password = null;
		public int Database = 0;
	}

	public RedisClass UserRedis = null;
	public ExternalServerClass ExternalServer = null;
	public InternalClientClass InternalClient = null;
	
	public MqConfig MqConfig = null;
	
	public PortalClass findPortalByPort(int port) {
		PortalClass result = null;
		for (PortalClass portal : this.ExternalServer.Portals) {
			if (portal.LocalPort == port) {
				result = portal;
				break;
			}
		}
		return result;
	}

}
